<!-- 舆情管理 -->
<template>
	<view class="situationView F8">
		<view class="Manage F"><text>舆情管理</text></view>
		<view class="showsituation-view F" v-for="(item, index) in list" :key="index" @click="goDetail(item.eventId, item.type)">
			<view class="showsituation-view1">
				<image class="card-img" :src="item.headPic" mode="aspectFill"></image>
			</view>
			<view class="showsituation-view2">
				<view class="showsituation-view1">
					<text class="card-name">{{ item.name }}</text>
					<text class="card-time">{{ item.warningTime }}</text>
				</view>
				
			<view class="showsituation-view3">
					<image class="img" src="../../static/tab2/position.png"></image>
					<text class="card-text" style="font-size:30upx ">{{ item.role == 1 ? '医生' : item.role == 2 ? '护士' : '患者' }}</text>
				</view>
				<view class="showsituation-view4 ">
					关键字
					<text class="keywords">{{ item.warningKeyword }}</text>
				</view>
			</view>

		</view>
		<text class="loadMore">{{ contentText }}</text>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				role: '',
				refreshing: false,
				fetchPageNum: 1,
				pullFlag: true,
				contentText: '上拉显示更多',
				pageSize: 10
			};
		},
		onShow() {
			this.fetchPageNum = 1;
			this.pullFlag = true;
			this.refreshing = false;
			console.log('请求token', uni.getStorageSync('token'));
			this.getData();
		},
		onReachBottom() {
			console.log('滑动到页面底部');
			this.contentText = '加载中...';
			if (this.pullFlag) {
				this.fetchPageNum += 1;
				this.pullData();
			} else {
				this.contentText = '暂无更多数据';
			}


		},
		onPullDownRefresh() {
			// this.reload=true;
			console.log('下拉刷新');
			// this.pullData();
			uni.startPullDownRefresh({
				//API开始下拉刷新操作
				success: res => {
					console.log('shuacin', this.fetchPageNum);
					this.refreshing = true;
					this.getData(); //下拉刷新重新获取数据
					uni.stopPullDownRefresh(); //API停止下拉刷

				}
			});
		},
		methods: {
			pullData() {
				console.log(this.fetchPageNum)
				uni.request({
					url: this.$serverUrl + '/app/hospital/publicSentiment/findSentimentManagerList', //仅为示例，并非真实接口地址。
					data: {
						pageNumber: this.fetchPageNum, //当前页数
						pageSize: this.pageSize
					},
					method: 'POST',
					header: {
						token: uni.getStorageSync('token'),
						'content-type': 'application/json',
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: (res) => {

						if (res.data.code == 0) {
							console.log("findSentimentManagerList == " + JSON.stringify(res));
							if (this.refreshing) {
								uni.showToast({
									title: '已经最新',
									icon: 'none'
								});
								this.refreshing = false;
								uni.stopPullDownRefresh();
								return;
							}
							let lists = [];
							let data = res.data.data;
							for (let i = 0; i < data.length; i++) {
								lists.push(data[i]);
							}
							if (lists.length < this.pageSize) {
								this.pullFlag = false;

							}
							console.log('得到lists', lists);

							// this.moneymanagerList= this.moneymanagerList.concat(lists);
							this.list = this.list.concat(lists);

							console.log(this.list);

						}
						try {
							uni.setStorageSync('data', JSON.stringify(res.data.data));
						} catch (e) {}
					}
				});
			},
			// 获得舆情管理列表的数据
			getData() {
				// this.update=false;
				// this.update=true;
				uni.request({
					url: this.$serverUrl + '/app/hospital/publicSentiment/findSentimentManagerList', //仅为示例，并非真实接口地址。
					data: {
						pageNumber: 1, //当前页数
						pageSize: this.pageSize
					},
					method: 'POST',
					header: {
						token: uni.getStorageSync('token'),
						'content-type': 'application/json',
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: (res) => {
						if (res.data.code == 0) {
							console.log(res.data);
							if (this.refreshing) {
								uni.showToast({
									title: '已经最新',
									icon: 'none'
								});
								this.refreshing = false;
								uni.stopPullDownRefresh();

								return;
							}
							let lists = [];
							let data = res.data.data;
							for (let i = 0; i < data.length; i++) {
								lists.push(data[i]);
							}
							if (lists.length < this.pageSize) {
								this.contentText = '暂无更多数据';
							}
							this.lists = res.data.data;
							console.log('得到lists', lists);
							if (this.refreshing) {
								this.refreshing = false;
								uni.stopPullDownRefresh();
								this.list = lists;

							} else {
								this.list = lists;
								console.info("this.fetchPageNum == " + this.fetchPageNum)
								// this.fetchPageNum += 1;
								console.log(this.list);
							}
						}
						try {
							uni.getStorageSync('data', JSON.stringify(res.data.data.token));
						} catch (e) {}
					}
				});
			},
			goDetail(eventId, type) {
				uni.navigateTo({
					url: 'situation-detail?eventId=' + eventId + '&&type=' + type
				});
				console.log(eventId);
				console.log(type);
			}
		}
	};
</script>

<style>
	.update {
		display: flex;
		flex: 1;
		flex-direction: column;
		min-height: 100vh;
	}
	.top{
		margin-top: 10upx;
	}
	.situationView {
		display: flex;
		flex: 1;
		flex-direction: column;
		min-height: 100vh;
	}

	/* 舆情管理 */
	.Manage {
		
		padding-top: 60upx;
		padding-bottom: 20upx;
		padding-left: 40upx;
		font-size: 40upx;
		margin-bottom: 10upx;
	}

	/* 显示视图 */
	.showsituation-view {
		margin-top: 5upx;
		flex-direction: row;
		width: inherit;
		height: 260upx;
		border-bottom-style: solid;
		border-bottom-width: 10upx;
		border-bottom-color: #f1f1f1;
		box-sizing: border-box;
	}
	.showsituation-view1{
		flex-direction: row;
	}
	.showsituation-view3{
		/* margin-top: 5upx; */
		flex-direction: row;
		align-items:center;
	}
	.showsituation-view2{
		
		flex-direction:column;
		padding-top: 15upx;
	}
	.showsituation-view4{
		margin-top: 40upx;
		flex-direction: row;
		align-items:center;
	}
	.card {
		background-color: #0079c3;
		flex-direction: row;
	}

	.card-img {
		flex-direction: row;
		margin: 30upx;
		width: 100upx;
		height: 100upx;
		border-radius: 80upx;
	}

	.card-name {
		position: relative;
		font-size: 30upx;
		margin-top: 40upx;
		flex-direction: row;
		width: 150upx;
		height: 50upx;
		background-color: #ffffff;
	}

	.card-time {
		height: 50upx;
		margin-top: 40upx;
		margin-left: 120upx;
		text-align: center;
		color: #c0c0c0;
		font-size: 28upx;
	}

	/* .card-text {
		font-size: 20upx;
	} */

	/* .card-identification {
		position: relative;
		width: 500upx;
		height: 40upx;
		margin: 90upx -557upx;
	} */

	.img {
		width: 30upx;
		height: 30upx;
		/* margin-top: 2upx; */
		/* margin-left: 30upx; */
	}

	/* 职位 */
	.card-text {
		/* width: 150upx;
		height: 150upx; */
		margin-left: 10upx;
		color: #c0c0c0;
		font-size: 26upx;
	}

	.keyword {
		width: 500upx;
		height: 50upx;
		margin-top: 170upx;
		margin-left: 57upx;
		font-size: 28upx;
	}

	.keywords {
		margin-left: 15upx;
		color: red;
		font-size: 28upx;
	}

	page,
	view {
		display: flex;
	}

	page {
		display: flex;
		min-height: 100%;
		background-color: #ffffff;
	}

	template {
		display: flex;
		flex: 1;
	}

	.loadMore {
		font-size: 30upx;
		color: #555;
		margin-bottom: 20upx;
		margin: 0 auto;
	}
</style>
